From 853063bea76f6c6add1b9775e8864a4cc119c835 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Jan 2020 09:09:22 -0500 Subject: [PATCH] Remove old drag dest api --- gtk/gtkdragdest.c | 300 +--------------------------------------------- gtk/gtkdragdest.h | 31 ----- gtk/gtkwidget.c | 248 -------------------------------------- gtk/gtkwidget.h | 23 ---- 4 files changed, 3 insertions(+), 599 deletions(-) diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c index 7968472eb5..d079c198d3 100644 --- a/gtk/gtkdragdest.c +++ b/gtk/gtkdragdest.c @@ -89,84 +89,7 @@ gtk_drag_dest_set_internal (GtkWidget *widget, site, gtk_drag_dest_site_destroy); } -/** - * gtk_drag_dest_set: (method) - * @widget: a #GtkWidget - * @flags: which types of default drag behavior to use - * @targets: (allow-none): the drop types that this @widget will - * accept, or %NULL. Later you can access the list with - * gtk_drag_dest_get_target_list() and gtk_drag_dest_find_target(). - * @actions: a bitmask of possible actions for a drop onto this @widget. - * - * Sets a widget as a potential drop destination, and adds default behaviors. - * - * The default behaviors listed in @flags have an effect similar - * to installing default handlers for the widget’s drag-and-drop signals - * (#GtkWidget::drag-motion, #GtkWidget::drag-drop, ...). They all exist - * for convenience. When passing #GTK_DEST_DEFAULT_ALL for instance it is - * sufficient to connect to the widget’s #GtkWidget::drag-data-received - * signal to get primitive, but consistent drag-and-drop support. - * - * Things become more complicated when you try to preview the dragged data, - * as described in the documentation for #GtkWidget::drag-motion. The default - * behaviors described by @flags make some assumptions, that can conflict - * with your own signal handlers. For instance #GTK_DEST_DEFAULT_DROP causes - * invokations of gdk_drag_status() in the context of #GtkWidget::drag-motion, - * and invokations of gdk_drag_finish() in #GtkWidget::drag-data-received. - * Especially the later is dramatic, when your own #GtkWidget::drag-motion - * handler calls gtk_drag_get_data() to inspect the dragged data. - * - * There’s no way to set a default action here, you can use the - * #GtkWidget::drag-motion callback for that. Here’s an example which selects - * the action to use depending on whether the control key is pressed or not: - * |[ - * static void - * drag_motion (GtkWidget *widget, - * GdkDrag *drag, - * gint x, - * gint y, - * guint time) - * { -* GdkModifierType mask; - * - * gdk_surface_get_pointer (gtk_native_get_surface (gtk_widget_get_native (widget)), - * NULL, NULL, &mask); - * if (mask & GDK_CONTROL_MASK) - * gdk_drag_status (context, GDK_ACTION_COPY, time); - * else - * gdk_drag_status (context, GDK_ACTION_MOVE, time); - * } - * ]| - */ -GtkDropTarget * -gtk_drag_dest_set (GtkWidget *widget, - GtkDestDefaults flags, - GdkContentFormats *targets, - GdkDragAction actions) -{ - GtkDragDestSite *site; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - site = g_slice_new0 (GtkDragDestSite); - - site->dest = gtk_drop_target_new (flags, targets, actions); - site->have_drag = FALSE; - - gtk_drag_dest_set_internal (widget, site); - - return site->dest; -} - -/** - * gtk_drag_dest_unset: (method) - * @widget: a #GtkWidget - * - * Clears information about a drop destination set with - * gtk_drag_dest_set(). The widget will no longer receive - * notification of drags. - */ -void +static void gtk_drag_dest_unset (GtkWidget *widget) { GtkDragDestSite *old_site; @@ -176,230 +99,13 @@ gtk_drag_dest_unset (GtkWidget *widget) old_site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest")); if (old_site) { - g_signal_handlers_disconnect_by_func (widget, - gtk_drag_dest_realized, - old_site); - g_signal_handlers_disconnect_by_func (widget, - gtk_drag_dest_hierarchy_changed, - old_site); + g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_realized, old_site); + g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_hierarchy_changed, old_site); } g_object_set_data (G_OBJECT (widget), I_("gtk-drag-dest"), NULL); } -/** - * gtk_drag_dest_get_target_list: (method) - * @widget: a #GtkWidget - * - * Returns the list of targets this widget can accept from - * drag-and-drop. - * - * Returns: (nullable) (transfer none): the #GdkContentFormats, or %NULL if none - */ -GdkContentFormats * -gtk_drag_dest_get_target_list (GtkWidget *widget) -{ - GtkDragDestSite *site; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest")); - - return site ? gtk_drop_target_get_formats (site->dest) : NULL; -} - -/** - * gtk_drag_dest_set_target_list: (method) - * @widget: a #GtkWidget that’s a drag destination - * @target_list: (allow-none): list of droppable targets, or %NULL for none - * - * Sets the target types that this widget can accept from drag-and-drop. - * The widget must first be made into a drag destination with - * gtk_drag_dest_set(). - */ -void -gtk_drag_dest_set_target_list (GtkWidget *widget, - GdkContentFormats *target_list) -{ - GtkDragDestSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest")); - - if (!site) - { - g_warning ("Can't set a target list on a widget until you've called gtk_drag_dest_set() " - "to make the widget into a drag destination"); - return; - } - - gtk_drop_target_set_formats (site->dest, target_list); -} - -/** - * gtk_drag_dest_add_text_targets: (method) - * @widget: a #GtkWidget that’s a drag destination - * - * Add the text targets supported by #GtkSelectionData to - * the target list of the drag destination. The targets - * are added with @info = 0. If you need another value, - * use gtk_target_list_add_text_targets() and - * gtk_drag_dest_set_target_list(). - */ -void -gtk_drag_dest_add_text_targets (GtkWidget *widget) -{ - GdkContentFormats *target_list; - - target_list = gtk_drag_dest_get_target_list (widget); - if (target_list) - gdk_content_formats_ref (target_list); - else - target_list = gdk_content_formats_new (NULL, 0); - target_list = gtk_content_formats_add_text_targets (target_list); - gtk_drag_dest_set_target_list (widget, target_list); - gdk_content_formats_unref (target_list); -} - -/** - * gtk_drag_dest_add_image_targets: (method) - * @widget: a #GtkWidget that’s a drag destination - * - * Add the image targets supported by #GtkSelectionData to - * the target list of the drag destination. The targets - * are added with @info = 0. If you need another value, - * use gtk_target_list_add_image_targets() and - * gtk_drag_dest_set_target_list(). - */ -void -gtk_drag_dest_add_image_targets (GtkWidget *widget) -{ - GdkContentFormats *target_list; - - target_list = gtk_drag_dest_get_target_list (widget); - if (target_list) - gdk_content_formats_ref (target_list); - else - target_list = gdk_content_formats_new (NULL, 0); - target_list = gtk_content_formats_add_image_targets (target_list, FALSE); - gtk_drag_dest_set_target_list (widget, target_list); - gdk_content_formats_unref (target_list); -} - -/** - * gtk_drag_dest_add_uri_targets: (method) - * @widget: a #GtkWidget that’s a drag destination - * - * Add the URI targets supported by #GtkSelectionData to - * the target list of the drag destination. The targets - * are added with @info = 0. If you need another value, - * use gtk_target_list_add_uri_targets() and - * gtk_drag_dest_set_target_list(). - */ -void -gtk_drag_dest_add_uri_targets (GtkWidget *widget) -{ - GdkContentFormats *target_list; - - target_list = gtk_drag_dest_get_target_list (widget); - if (target_list) - gdk_content_formats_ref (target_list); - else - target_list = gdk_content_formats_new (NULL, 0); - target_list = gtk_content_formats_add_uri_targets (target_list); - gtk_drag_dest_set_target_list (widget, target_list); - gdk_content_formats_unref (target_list); -} - -/** - * gtk_drag_dest_set_track_motion: (method) - * @widget: a #GtkWidget that’s a drag destination - * @track_motion: whether to accept all targets - * - * Tells the widget to emit #GtkWidget::drag-motion and - * #GtkWidget::drag-leave events regardless of the targets and the - * %GTK_DEST_DEFAULT_MOTION flag. - * - * This may be used when a widget wants to do generic - * actions regardless of the targets that the source offers. - */ -void -gtk_drag_dest_set_track_motion (GtkWidget *widget, - gboolean track_motion) -{ - GtkDragDestSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest")); - - g_return_if_fail (site != NULL); - - gtk_drop_target_set_track_motion (site->dest, track_motion); -} - -/** - * gtk_drag_dest_get_track_motion: (method) - * @widget: a #GtkWidget that’s a drag destination - * - * Returns whether the widget has been configured to always - * emit #GtkWidget::drag-motion signals. - * - * Returns: %TRUE if the widget always emits - * #GtkWidget::drag-motion events - */ -gboolean -gtk_drag_dest_get_track_motion (GtkWidget *widget) -{ - GtkDragDestSite *site; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - - site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest")); - - if (site) - return gtk_drop_target_get_track_motion (site->dest); - - return FALSE; -} - -/** - * gtk_drag_dest_find_target: (method) - * @widget: drag destination widget - * @drop: #GdkDrop - * @target_list: (allow-none): list of droppable targets, or %NULL to use - * gtk_drag_dest_get_target_list (@widget). - * - * Looks for a match between the supported targets of @drop and the - * @dest_target_list, returning the first matching target, otherwise - * returning %NULL. @dest_target_list should usually be the return - * value from gtk_drag_dest_get_target_list(), but some widgets may - * have different valid targets for different parts of the widget; in - * that case, they will have to implement a drag_motion handler that - * passes the correct target list to this function. - * - * Returns: (transfer none) (nullable): first target that the source offers - * and the dest can accept, or %NULL - */ -const char * -gtk_drag_dest_find_target (GtkWidget *widget, - GdkDrop *drop, - GdkContentFormats *target_list) -{ - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - g_return_val_if_fail (GDK_IS_DROP (drop), NULL); - - if (target_list == NULL) - target_list = gtk_drag_dest_get_target_list (widget); - - if (target_list == NULL) - return NULL; - - return gdk_content_formats_match_mime_type (target_list, - gdk_drop_get_formats (drop)); -} - /** * SECTION:gtkdroptarget diff --git a/gtk/gtkdragdest.h b/gtk/gtkdragdest.h index 4ef71ea6b8..5c48fd7227 100644 --- a/gtk/gtkdragdest.h +++ b/gtk/gtkdragdest.h @@ -68,37 +68,6 @@ typedef enum { GTK_DEST_DEFAULT_ALL = 0x07 } GtkDestDefaults; -GDK_AVAILABLE_IN_ALL -GtkDropTarget *gtk_drag_dest_set (GtkWidget *widget, - GtkDestDefaults flags, - GdkContentFormats *targets, - GdkDragAction actions); - -GDK_AVAILABLE_IN_ALL -void gtk_drag_dest_unset (GtkWidget *widget); - -GDK_AVAILABLE_IN_ALL -const char * gtk_drag_dest_find_target (GtkWidget *widget, - GdkDrop *drop, - GdkContentFormats *target_list); -GDK_AVAILABLE_IN_ALL -GdkContentFormats* gtk_drag_dest_get_target_list (GtkWidget *widget); -GDK_AVAILABLE_IN_ALL -void gtk_drag_dest_set_target_list (GtkWidget *widget, - GdkContentFormats *target_list); -GDK_AVAILABLE_IN_ALL -void gtk_drag_dest_add_text_targets (GtkWidget *widget); -GDK_AVAILABLE_IN_ALL -void gtk_drag_dest_add_image_targets (GtkWidget *widget); -GDK_AVAILABLE_IN_ALL -void gtk_drag_dest_add_uri_targets (GtkWidget *widget); - -GDK_AVAILABLE_IN_ALL -void gtk_drag_dest_set_track_motion (GtkWidget *widget, - gboolean track_motion); -GDK_AVAILABLE_IN_ALL -gboolean gtk_drag_dest_get_track_motion (GtkWidget *widget); - #define GTK_TYPE_DROP_TARGET (gtk_drop_target_get_type ()) #define GTK_DROP_TARGET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_DROP_TARGET, GtkDropTarget)) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 13aeaf2213..76de31262a 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -517,10 +517,6 @@ enum { MNEMONIC_ACTIVATE, MOVE_FOCUS, KEYNAV_FAILED, - DRAG_LEAVE, - DRAG_MOTION, - DRAG_DROP, - DRAG_DATA_RECEIVED, POPUP_MENU, ACCEL_CLOSURES_CHANGED, DISPLAY_CHANGED, @@ -1646,250 +1642,6 @@ gtk_widget_class_init (GtkWidgetClass *klass) G_TYPE_FROM_CLASS (klass), _gtk_marshal_BOOLEAN__ENUMv); - /** - * GtkWidget::drag-leave: - * @widget: the object which received the signal. - * @context: the drag context - * @time: the timestamp of the motion event - * - * The ::drag-leave signal is emitted on the drop site when the cursor - * leaves the widget. A typical reason to connect to this signal is to - * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting - * with gtk_drag_unhighlight(). - * - * - * Likewise, the #GtkWidget::drag-leave signal is also emitted before the - * ::drag-drop signal, for instance to allow cleaning up of a preview item - * created in the #GtkWidget::drag-motion signal handler. - */ - widget_signals[DRAG_LEAVE] = - g_signal_new (I_("drag-leave"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkWidgetClass, drag_leave), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - GDK_TYPE_DROP); - - /** - * GtkWidget::drag-motion: - * @widget: the object which received the signal - * @drop: the #GdkDrop - * @x: the x coordinate of the current cursor position - * @y: the y coordinate of the current cursor position - * - * The ::drag-motion signal is emitted on the drop site when the user - * moves the cursor over the widget during a drag. The signal handler - * must determine whether the cursor position is in a drop zone or not. - * If it is not in a drop zone, it returns %FALSE and no further processing - * is necessary. Otherwise, the handler returns %TRUE. In this case, the - * handler is responsible for providing the necessary information for - * displaying feedback to the user, by calling gdk_drag_status(). - * - * If the decision whether the drop will be accepted or rejected can't be - * made based solely on the cursor position and the type of the data, the - * handler may inspect the dragged data by calling gtk_drag_get_data() and - * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received - * handler. Note that you must pass #GTK_DEST_DEFAULT_DROP, - * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set() - * when using the drag-motion signal that way. - * - * Also note that there is no drag-enter signal. The drag receiver has to - * keep track of whether he has received any drag-motion signals since the - * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as - * an "enter" signal. Upon an "enter", the handler will typically highlight - * the drop site with gtk_drag_highlight(). - * |[ - * static void - * drag_motion (GtkWidget *widget, - * GdkDrop *drop, - * gint x, - * gint y, - * { - * GdkAtom target; - * - * PrivateData *private_data = GET_PRIVATE_DATA (widget); - * - * if (!private_data->drag_highlight) - * { - * private_data->drag_highlight = 1; - * gtk_drag_highlight (widget); - * } - * - * target = gtk_drag_dest_find_target (widget, drop, NULL); - * if (target == NULL) - * gdk_drop_status (drop, 0); - * else - * { - * private_data->pending_status - * = gdk_drop_get_actions (drop); - * gtk_drag_get_data (widget, drop, target); - * } - * - * return TRUE; - * } - * - * static void - * drag_data_received (GtkWidget *widget, - * GdkDrop *drop, - * GtkSelectionData *selection_data) - * { - * PrivateData *private_data = GET_PRIVATE_DATA (widget); - * - * if (private_data->suggested_action) - * { - * private_data->suggested_action = 0; - * - * // We are getting this data due to a request in drag_motion, - * // rather than due to a request in drag_drop, so we are just - * // supposed to call gdk_drag_status(), not actually paste in - * // the data. - * - * str = gtk_selection_data_get_text (selection_data); - * if (!data_is_acceptable (str)) - * gdk_drop_status (drop, 0); - * else - * gdk_drag_status (drop, GDK_ACTION_ALL); - * } - * else - * { - * // accept the drop - * } - * } - * ]| - * - * Returns: whether the cursor position is in a drop zone - */ - widget_signals[DRAG_MOTION] = - g_signal_new (I_("drag-motion"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkWidgetClass, drag_motion), - _gtk_boolean_handled_accumulator, NULL, - _gtk_marshal_BOOLEAN__OBJECT_INT_INT, - G_TYPE_BOOLEAN, 3, - GDK_TYPE_DROP, - G_TYPE_INT, - G_TYPE_INT); - g_signal_set_va_marshaller (widget_signals[DRAG_MOTION], - G_TYPE_FROM_CLASS (klass), - _gtk_marshal_BOOLEAN__OBJECT_INT_INTv); - - /** - * GtkWidget::drag-drop: - * @widget: the object which received the signal - * @drop: the #GdkDrop - * @x: the x coordinate of the current cursor position - * @y: the y coordinate of the current cursor position - * - * The ::drag-drop signal is emitted on the drop site when the user drops - * the data onto the widget. The signal handler must determine whether - * the cursor position is in a drop zone or not. If it is not in a drop - * zone, it returns %FALSE and no further processing is necessary. - * Otherwise, the handler returns %TRUE. In this case, the handler must - * ensure that gdk_drag_finish() is called to let the source know that - * the drop is done. The call to gdk_drag_finish() can be done either - * directly or in a #GtkWidget::drag-data-received handler which gets - * triggered by calling gtk_drag_get_data() to receive the data for one - * or more of the supported targets. - * - * Returns: whether the cursor position is in a drop zone - */ - widget_signals[DRAG_DROP] = - g_signal_new (I_("drag-drop"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkWidgetClass, drag_drop), - _gtk_boolean_handled_accumulator, NULL, - _gtk_marshal_BOOLEAN__OBJECT_INT_INT, - G_TYPE_BOOLEAN, 3, - GDK_TYPE_DROP, - G_TYPE_INT, - G_TYPE_INT); - g_signal_set_va_marshaller (widget_signals[DRAG_DROP], - G_TYPE_FROM_CLASS (klass), - _gtk_marshal_BOOLEAN__OBJECT_INT_INTv); - - /** - * GtkWidget::drag-data-received: - * @widget: the object which received the signal - * @drop: the #GdkDrop - * @x: where the drop happened - * @y: where the drop happened - * @data: the received data - * - * The ::drag-data-received signal is emitted on the drop site when the - * dragged data has been received. If the data was received in order to - * determine whether the drop will be accepted, the handler is expected - * to call gdk_drag_status() and not finish the drag. - * If the data was received in response to a #GtkWidget::drag-drop signal - * (and this is the last target to be received), the handler for this - * signal is expected to process the received data and then call - * gdk_drag_finish(), setting the @success parameter depending on - * whether the data was processed successfully. - * - * Applications must create some means to determine why the signal was emitted - * and therefore whether to call gdk_drag_status() or gdk_drag_finish(). - * - * The handler may inspect the selected action with - * gdk_drag_context_get_selected_action() before calling - * gdk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as - * shown in the following example: - * |[ - * void - * drag_data_received (GtkWidget *widget, - * GdkDrop *drop, - * GtkSelectionData *data) - * { - * if ((data->length >= 0) && (data->format == 8)) - * { - * GdkDragAction action; - * - * // handle data here - * - * action = gdk_drop_get_actions (drop); - * if (!gdk_drag_action_is_unique (action)) - * { - * GtkWidget *dialog; - * gint response; - * - * dialog = gtk_message_dialog_new (NULL, - * GTK_DIALOG_MODAL | - * GTK_DIALOG_DESTROY_WITH_PARENT, - * GTK_MESSAGE_INFO, - * GTK_BUTTONS_YES_NO, - * "Move the data ?\n"); - * response = gtk_dialog_run (GTK_DIALOG (dialog)); - * gtk_widget_destroy (dialog); - * - * if (response == GTK_RESPONSE_YES) - * action = GDK_ACTION_MOVE; - * else - * action = GDK_ACTION_COPY; - * } - * - * gdk_drop_finish (context, action); - * } - * else - * gdk_drop_finish (context, 0); - * } - * ]| - */ - widget_signals[DRAG_DATA_RECEIVED] = - g_signal_new (I_("drag-data-received"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_BOXED, - G_TYPE_NONE, 2, - GDK_TYPE_DROP, - GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE); - g_signal_set_va_marshaller (widget_signals[DRAG_DATA_RECEIVED], - G_TYPE_FROM_CLASS (klass), - _gtk_marshal_VOID__OBJECT_BOXEDv); - /** * GtkWidget::query-tooltip: * @widget: the object which received the signal diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 47dc7fc0ad..fc1221fc81 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -187,14 +187,6 @@ struct _GtkWidget * @focus: * @move_focus: Signal emitted when a change of focus is requested * @keynav_failed: Signal emitted if keyboard navigation fails. - * @drag_leave: Signal emitted on the drop site when the cursor leaves - * the widget. - * @drag_motion: signal emitted on the drop site when the user moves - * the cursor over the widget during a drag. - * @drag_drop: Signal emitted on the drop site when the user drops the - * data onto the widget. - * @drag_data_received: Signal emitted on the drop site when the - * dragged data has been received. * @popup_menu: Signal emitted whenever a widget should pop up a * context menu. * @get_accessible: Returns the accessible object that describes the @@ -266,21 +258,6 @@ struct _GtkWidgetClass gboolean (* keynav_failed) (GtkWidget *widget, GtkDirectionType direction); - /* Target side drag signals */ - void (* drag_leave) (GtkWidget *widget, - GdkDrop *drop); - gboolean (* drag_motion) (GtkWidget *widget, - GdkDrop *drop, - gint x, - gint y); - gboolean (* drag_drop) (GtkWidget *widget, - GdkDrop *drop, - gint x, - gint y); - void (* drag_data_received) (GtkWidget *widget, - GdkDrop *drop, - GtkSelectionData *selection_data); - /* Signals used only for keybindings */ gboolean (* popup_menu) (GtkWidget *widget); -- 2.30.2